package controller

import (
	"github.com/dgrijalva/jwt-go"
	"github.com/labstack/echo/v4"
	"law_case_api/models"
	"law_case_api/services"
	"net/http"
	"strconv"
)

// GetDashboardData
// @Summary 看板上的几个数据集合
// @Tags 数据分析管理
// @Accept plain
// @Produce plain
// @Success 200 {object} models.BaseResult
// @Failure 400 {object} models.BaseResult
// @Router /wzj/data/get [get]
func GetDashboardData(c echo.Context) error {
	resp := models.BaseResult{
		Code: 200,
	}
	user := c.Get("user").(*jwt.Token)
	claims := user.Claims.(*models.JwtCustomClaims)
	userid, _ := strconv.Atoi(claims.UserId)
	if userid == 0 {
		resp.Code = 400
		resp.Message = "用户信息不存在，请重新登录"
		return c.JSON(http.StatusOK, resp)
	}
	data := services.DataService{}
	resp.Data = data.GetDashboardData()
	return c.JSON(http.StatusOK, resp)
}

// GetDashboardCaseData
// @Summary 开庭排期记录
// @Tags 数据分析管理
// @Accept plain
// @Produce plain
// @Success 200 {object} models.BaseResult
// @Failure 400 {object} models.BaseResult
// @Router /wzj/data/case [get]
func GetDashboardCaseData(c echo.Context) error {
	resp := models.BaseResult{
		Code: 200,
	}
	user := c.Get("user").(*jwt.Token)
	claims := user.Claims.(*models.JwtCustomClaims)
	userid, _ := strconv.Atoi(claims.UserId)
	if userid == 0 {
		resp.Code = 400
		resp.Message = "用户信息不存在，请重新登录"
		return c.JSON(http.StatusOK, resp)
	}
	_case := services.CaseService{}
	resp.Data = _case.GetNeedCountList()
	return c.JSON(http.StatusOK, resp)
}
